package com.itheima.web; /**
 * @author tongchen
 * @create 2022-11-30 19:32
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.net.URLDecoder;

@WebServlet("/bServlet")
public class BServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //3.获取cookie数组
        Cookie[] cookies = request.getCookies();

        //4.选择cookie
        for (Cookie co:cookies
        ) {
            //进行解码操作
            if("userName".equals(co.getName())){
                System.out.println(co.getName()+ URLDecoder.decode(co.getValue(),"utf-8"));
                break;
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
